package com.bw.dao.impl;

import com.bw.dao.CustomerDao;
import com.bw.pojo.vo.CustomerVo;

import java.util.List;

public class CustomerDaoImpl extends BaseDao implements CustomerDao {

    @Override
    public List<CustomerVo> getCustomerList(CustomerVo customerVo) {
        String sql = "select * from t_customer where true";
        if(null != customerVo.getCustomerName()&&!customerVo.getCustomerName().isEmpty()){
            sql += " and INSTR(customer_name,'"+customerVo.getCustomerName()+"')";
        }
        //分页 limit
        sql += " limit ?,?";
        int index = (customerVo.getPageNum() - 1) * customerVo.getPageSize();
        List<CustomerVo> list = baseQueryList(CustomerVo.class, sql, index, customerVo.getPageSize());
        return list;
    }

    @Override
    public int getCount(CustomerVo customerVo) {
        String sql = "select count(1) from t_customer where true ";
        if(null != customerVo.getCustomerName()&&!customerVo.getCustomerName().isEmpty()){
            sql += " and INSTR(customer_name,'"+customerVo.getCustomerName()+"')";
        }
        Long aLong = baseQueryCount(Long.class, sql);
        return aLong.intValue();
    }
}
